package com.edu.coder.xcz.homwork5.t6;

public class abstractTest {
    public static void main(String[] args) {
        /********* begin *********/
        // 分别实例化Student类与Worker类的对象，并调用各自构造方法初始化类属性。
        Student student = new Student("张三", 20, "学生");
        Worker worker = new Worker("李四", 30, "工人");
        // 分别调用各自类中被复写的talk()方法 打印信息。
        student.talk();
        worker.talk();
        /********* end *********/

    }
}

// 声明一个名为Person的抽象类，在Person中声明了三个属性name age occupation和一个抽象方法——talk()。
abstract class Person {
    /********* begin *********/
    private String name;
    private Integer age;
    private String occupation;

    public Person(String name, Integer age, String occupation) {
        this.name = name;
        this.age = age;
        this.occupation = occupation;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getOccupation() {
        return occupation;
    }

    public void setOccupation(String occupation) {
        this.occupation = occupation;
    }

    abstract public void talk();
    /********* end *********/
}

// Student类继承自Person类，添加带三个参数的构造方法，复写talk()方法 返回姓名、年龄和职业信息
class Student extends Person {

    /********* begin *********/
    public Student(String name, Integer age, String occupation) {
        super(name, age, occupation);
    }

    @Override
    public void talk() {
        System.out.println("学生——>姓名：" + getName() + "，年龄：" + getAge() + "，职业：" + getOccupation() + "！");
    }
    /********* end *********/
}

// Worker类继承自Person类，添加带三个参数的构造方法，复写talk()方法 返回姓名、年龄和职业信息
class Worker extends Person {
    /********* begin *********/
    public Worker(String name, Integer age, String occupation) {
        super(name, age, occupation);
    }

    @Override
    public void talk() {
        System.out.println("工人——>姓名：" + getName() + "，年龄：" + getAge() + "，职业：" + getOccupation() + "！");
    }
    /********* end *********/

}